package com.test;

import com.connection.DataConnection;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class ProductDetail extends Activity {

	private ImageView img;
	private TextView product_name, product_price, product_info;
	private EditText count;
	private Button add, check;
	
	int sum;
	
	
	DataConnection data = new DataConnection(this);

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.productdetail);

		data.open();

		product_name = (TextView) findViewById(R.id.ProductName);
		product_price = (TextView) findViewById(R.id.ProductPrice);
		product_info = (TextView) findViewById(R.id.ProductInfo);
		img = (ImageView) findViewById(R.id.image);
		count = (EditText) findViewById(R.id.ProductCount);
		
		if (ProductActivity.proPicture!=null&&ProductActivity.proPicture.length() > 0) {
			Bitmap bitmap = BitmapFactory.decodeFile(ProductActivity.proPicture);
			img.setImageBitmap(bitmap);
			product_price.setText(ProductActivity.proPrice);
			product_name.setText(ProductActivity.proName);
			product_info.setText(ProductActivity.proIntroduction);
			
		}
		
		add = (Button) findViewById(R.id.add);
		add.setOnClickListener(new OnClickListener(){
			
			public void onClick(View arg0) {
				
				sum = Integer.parseInt(product_price.getText().toString())*Integer.parseInt(count.getText().toString());
				
				System.out.println("money: "+sum+"     good nbr:  "+count.getText().toString()+"  good price:  "+product_name.getText().toString());
				System.out.println("User name: "+UserActivity.tmpName);
				
				String userName= UserActivity.tmpName;
				String productName = product_name.getText().toString();
				String amount = count.getText().toString();
				String price = String.valueOf(sum);
				
				data.addOrderInfo(userName, productName, amount, price);
				data.close();
				System.out.println(userName+"  "+productName+"  "+amount+"  "+price);
			}
			
		});
		
		check = (Button) findViewById(R.id.check);
		check.setOnClickListener(new OnClickListener(){
			
			public void onClick(View arg0) {
				
				startActivity(new Intent(ProductDetail.this, BasketActivity.class));

			}
			
		});
		
		
		
	}

}
